package com.caowj.composedemo.activity

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import com.caowj.composedemo.ui.theme.ComposeDemoTheme

@Deprecated("废弃了")
class IndexActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeDemoTheme {
                // A surface container using the 'background' color from the theme
                Scaffold(
                    topBar = { TopAppBar(title = { Text(text = "Compose学习") }) },
                    content = {
                        val msgList = mutableListOf<String>()
                        for (i in 0..20) {
                            msgList.add("Index_${i + 1}")
                        }
                        messageList(messages = msgList)
                    }
                )
            }
        }
    }

    @Composable
    fun messageList(messages: List<String>) {// 值可以是 List或者Array两种方式
        LazyColumn {
//            items(messages.size) { message ->//遍历索引的方式
//                Text(text = messages[message])
//            }
//           items(items = messages){ message -> //遍历内容
//               Text(text = message)
//           }
            itemsIndexed(items = messages) { index, item -> //遍历内容和索引
                Text(text = "索引:$index -- 内容:$item")
            }
        }
    }

}

